package com.service.admin.member.controller;

import com.service.admin.member.controller.rep.FeedbackDetailRep;
import com.service.admin.member.controller.rep.FeedbackPageRep;
import com.service.admin.member.controller.req.FeedbackPageReq;
import com.service.admin.member.controller.req.FeedbackReplyReq;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.CommonPageRep;
import com.service.core.rest.response.OneResponse;
import com.service.core.rest.response.PageResponse;
import com.service.admin.member.service.FeedbackService;
import com.service.utility.common.UUIDUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 会员反馈表
 *
 * @author xxxx
 * @email xxxx@qq.com
 * @date 2019-11-11 09:26:11
 */
@Slf4j
@RestController
@RequestMapping("feedback")
public class FeedbackController extends BaseController {
    @Autowired
    private FeedbackService feedbackService;


    @ApiOperation("分页查看反馈")
    @PostMapping("page")
    public PageResponse page(@RequestBody @Validated FeedbackPageReq pageReq) {
        String uuid = UUIDUtil.randomUUID();
        log.info("分页查看反馈 请求开始: 请求参数：{}，UUID:{}", pageReq, uuid);
        CommonPageRep<FeedbackPageRep> result = feedbackService.pageFeedback(pageReq);
        log.info("分页查看反馈 请求结束: UUID:{}", uuid);
        return successQueryPageResponse(result);
    }

    @GetMapping("detail/{id}")
    public OneResponse detail(@PathVariable("id") Integer feedbackId) {
        String uuid = UUIDUtil.randomUUID();
        log.info("回复反馈 请求开始: 请求参数:{}, UUID:{}", feedbackId, uuid);
        FeedbackDetailRep result = feedbackService.getDetailById(feedbackId);
        log.info("回复反馈 请求结束: UUID:{}", uuid);
        return successQueryOneResponse(result);
    }

    @PostMapping("reply/{id}")
    public BaseResponse reply(@PathVariable("id") Integer feedbackId,@RequestBody FeedbackReplyReq ReplyReq) {
        String uuid = UUIDUtil.randomUUID();
        ReplyReq.setFeedbackId(feedbackId);
        log.info("回复反馈 请求开始: 请求参数:{}, UUID:{}", ReplyReq, uuid);
        feedbackService.replyFeedback(ReplyReq);
        log.info("回复反馈 请求结束: UUID:{}", uuid);
        return successUpdateBaseResponse();
    }


}